Imports System.Data.SqlClient
Public Class CheckListBoxDemo

    Private Sub CheckListBoxDemo_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim folder As String() = System.IO.Directory.GetDirectories("C:\Windows")
        Me.CheckedListBox1.DataSource = folder

        Dim conn As New SqlConnection()
        conn.ConnectionString = " user id=sa;pwd=;data source=.;initial catalog=Northwind"
        Dim da As New SqlDataAdapter("SELECT ProductID, ProductName FROM Products", conn)
        Dim table As New DataTable
        da.Fill(table)

        CheckedListBox2.DataSource = table
        CheckedListBox2.DisplayMember = "ProductName"
        CheckedListBox2.ValueMember = "ProductID"


    End Sub

    Private Sub CheckedListBox1_ItemCheck(ByVal sender As Object, ByVal e As System.Windows.Forms.ItemCheckEventArgs) Handles CheckedListBox1.ItemCheck
        If e.NewValue = CheckState.Checked Then
            Me.Text = CheckedListBox1.Text
        End If
    End Sub

    
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim strValues As String = ""
        ' Duyeät qua töøng phaàn töû ñaõ choïn
        For Each item As Object In CheckedListBox2.CheckedItems
            strValues = strValues + item("ProductName") + ","
        Next
        MsgBox("Sản phẩm : " + strValues)

    End Sub
End Class
